package com.vincent.sciinfo.controller;

import com.vincent.sciinfo.pojo.Message;
import com.vincent.sciinfo.pojo.TSMResult;
import com.vincent.sciinfo.service.MessageService;
import com.vincent.sciinfo.utils.StatusCode;
import com.vincent.sciinfo.utils.StatusMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageServer;

    //查询管理员发给全体教师的消息
    @RequestMapping("/sel_sys_msg")
    public TSMResult selectSystemMsg(){
        TSMResult tsmResult = new TSMResult();
        List<Message> list = messageServer.selectSystemMsg();
        tsmResult.setCode(StatusCode.SUCCESS);
        tsmResult.setMessage(StatusMessage.SUCCESS);
        tsmResult.setData(list);
        return tsmResult;
    }

    @RequestMapping("/sel_personal_msg")
    public TSMResult selectPersonalMsg(@RequestParam("teacherId") String teacherId){
        TSMResult tsmResult = new TSMResult();
        List<Message> list = messageServer.selectMsgByTeacherId(teacherId);
        tsmResult.setCode(StatusCode.SUCCESS);
        tsmResult.setMessage(StatusMessage.SUCCESS);
        tsmResult.setData(list);
        return tsmResult;
    }

    @RequestMapping("/insertMessage")
    public int insertMessage(@RequestBody Message message){
        return messageServer.insertMessage(message);
    }
}
